//
//  DEveryXDayCell.swift
//  Drop
//
//  Created by hushaohua on 2018/5/28.
//  Copyright © 2018年 init. All rights reserved.
//

import UIKit

class DEveryXDayCell: UICollectionViewCell {
    override init(frame: CGRect) {
        super.init(frame: frame);
        self.contentView.addSubview(self.textLabel);
        self.addLayoutConstraints();
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func useAsWeekday(_ selected:Bool) {
        if (!selected){
            self.textLabel.backgroundColor = UIColor.white;
            self.textLabel.textColor = UIColor.gray;
            self.textLabel.layer.cornerRadius = 5;
            self.textLabel.layer.masksToBounds = true;
            self.textLabel.layer.borderColor = UIColor(white: 0.92, alpha: 1).cgColor;
            self.textLabel.layer.borderWidth = 1;
        }else{
            self.textLabel.backgroundColor = UIColor.h_blue();
            self.textLabel.textColor = UIColor.white;
            self.textLabel.layer.cornerRadius = 5;
            self.textLabel.layer.masksToBounds = true;
            self.textLabel.layer.borderColor = UIColor.h_blue().cgColor;
        }
    }
    func useAsMonthday(_ selected:Bool) {
        if (selected){
            self.textLabel.backgroundColor = UIColor.h_blue();
            self.textLabel.textColor = UIColor.white;
        }else{
            self.textLabel.backgroundColor = UIColor.white;
            self.textLabel.textColor = UIColor.gray;
        }
    }
    
    lazy var textLabel:UILabel = {
        let label:UILabel = UILabel(frame: .zero);
        label.textAlignment = .center;
        label.translatesAutoresizingMaskIntoConstraints = false;
        
        return label;
    }();
    
    func addLayoutConstraints() {
        let views = ["text" : self.textLabel];
        var constraints:[NSLayoutConstraint] = [NSLayoutConstraint]();
        constraints += NSLayoutConstraint.constraints(withVisualFormat: "H:|-0-[text]-0-|", options: .directionLeadingToTrailing, metrics: nil, views: views);
        constraints += NSLayoutConstraint.constraints(withVisualFormat: "V:|-0-[text]-0-|", options: .directionLeadingToTrailing, metrics: nil, views: views);
        NSLayoutConstraint.activate(constraints);
    }
}
